<!--
 * Tencent is pleased to support the open source community by making Tars available.
 *
 * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
 *
 * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * https://opensource.org/licenses/BSD-3-Clause
 *
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
-->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap_table.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../js/jquery.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/bootstrap_table.min.js"></script>
    <script src="../js/template.js"></script>
    <script src="../js/common.js?v=20161228"></script>
    <script src="../js/server_list.js?v=20170112"></script>
</head>
<body>
<div class="table-box">
    <h4 class="sub-header">服务列表</h4>
    <div id="table-box" class="mt10"></div>

    <div id="cur-status-container">
        <h4 class="sub-header">服务实时状态</h4>
        <div id="cur-status-box"><table id="dyTable"></table></div>
    </div>
</div>

<div id="dlg-view-service" style="display: none">
    系统出错
</div>

<div id="dlg-ret" style="display: none;"></div>

<div id="patch_server" style="display: none;">

</div>

<div id="dlg-update-service" class="form-horizontal" style="display:none">
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100">服务名</label></div>
        <div class="col-sm-4">
            <div id="u-service-name"></div>
        </div>
        <div class="col-sm-2"><label class="tr wp100">部署节点</label></div>
        <div class="col-sm-4">
            <div id="u-node-name" style="white-space:normal;word-break:break-all;"></div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">是否备机</label></div>
        <div class="col-sm-4">
            <label class="control-label"><input type="radio" name="is_bak" value="true"> 是</label>
            <label class="control-label ml10"><input type="radio" name="is_bak" value="false"> 否</label>
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">模板名称</label></div>
        <div class="col-sm-4">
            <select name="" id="u-template-name" class="form-control"></select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">服务类型</label></div>
        <div class="col-sm-4">
            <select name="" id="u-server-type" class="form-control">
                <option value="tars_cpp">tars_cpp</option>
                <option value="tars_java">tars_java</option>
                <option value="tars_nodejs">tars_nodejs</option>
                <option value="tars_php">tars_php</option>
                <option value="not_tars">not_tars</option>
            </select>
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">启用Set</label></div>
        <div class="col-sm-4">
            <label class="control-label"><input type="radio" name="u_enable_set" value="true"> 是</label>
            <label class="control-label ml10"><input type="radio" name="u_enable_set" value="false"> 否</label>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">Set名 <span class="text-danger">*</span></label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control set-control" id="u-set-name" placeholder="全英文，全小写" disabled>
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">Set区域 <span class="text-danger">*</span></label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control set-control" id="u-set-area" placeholder="全英文，全小写" disabled>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">Set组 <span class="text-danger">*</span></label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control set-control" id="u-set-group" placeholder="数字 或者*号" disabled>
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">异步线程数</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control num-input" id="u-async-thread" placeholder="NodeJS的>=1，其他>=3">
        </div>
		
        <div class="col-sm-2"><label class="tr wp100 control-label">流量设置</label></div>
        <div class="col-sm-4">
            <select name="" id="u-grid_flag" class="form-control">
                <option value="NORMAL">NORMAL</option>
                <option value="NO_FLOW">NO_FLOW</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">缺省路径</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="u-base-path">
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">EXE路径</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="u-exe-path">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">启动脚本</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="u-start-path">
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">停止脚本</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="u-stop-path">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">监控脚本</label></div>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="u-monitor-path">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">私有模板</label></div>
        <div class="col-sm-10">
            <textarea class="form-control" id="u-profile" rows="4"></textarea>
        </div>
    </div>
</div>

<div id="dlg-servant" style="display:none">
    <div class="tool-bar">
        <div class="btn-group">
            <button type="button" class="btn btn-sm btn-primary" onclick="addAdapter()">添加Servant</button>
        </div>
    </div>
    <div id="servant-box" class="mt10"></div>
</div>

<div id="dlg-add-servant" class="form-horizontal" style="display: none;">
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">应用·服务名 </label></div>
        <div class="col-sm-10" id="a-server-name"></div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">OBJ名称 <span class="text-danger">*</span></label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="a-servant-name" placeholder="全英文，前面不用加应用·服务名">
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">线程数</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control num-input" id="a-thread-num">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">绑定地址 <span class="text-danger">*</span></label></div>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="a-end-point" placeholder="范例：tcp -h 172.27.205.40 -t 60000 -p 12000 -e 0">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">最大连接数</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control  num-input" id="a-max-connections" value="200000">
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">队列长度</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control num-input" id="a-queuecap" value="10000">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">队列超时(ms)</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control num-input" id="a-queuetimeout" value="60000">
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">允许IP</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="a-allow-ip">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-2"><label class="tr wp100 control-label">协议</label></div>
        <div class="col-sm-4">
            <label><input type="radio" name="a-protocol" value="tars" checked> TARS</label>
            <label class="ml10"><input type="radio" name="a-protocol" value="not_tars"> 非TARS</label>
        </div>
        <div class="col-sm-2"><label class="tr wp100 control-label">处理组</label></div>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="a-handlegroup">
        </div>
    </div>
</div>

<div id="dlg-patch-server" style="display: none;">
    <div class="tool-bar">
        <div class="btn-group">
            <button type="button" class="btn btn-sm btn-primary">发布服务</button>
        </div>
    </div>
    <div id="patch-server-list" class="mt10"></div>
</div>

<!--上传发布包-->
<div id="dlg-upload-patch" class="form-horizontal" style="display:none">
    <form enctype="multipart/form-data" id="uploadForm">
        <input type="hidden" name="application" id="up-application" value="">
        <input type="hidden" name="module_name" id="up-server-name" value="">
        <div class="form-group">
            <div class="col-sm-2"><label class="tr wp100 control-label">发布包</label></div>
            <div class="col-sm-10">
                <input id="file" type="file" name="suse" class="form-control"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2"><label class="tr wp100 control-label">备注</label></div>
            <div class="col-sm-10">
                <textarea name="comment" id="" class="form-control" rows="3"></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2"></div>
            <div class="col-sm-10">
                <button type="button" id="upload" class="btn btn-primary btn-sm">上传</button>
            </div>
        </div>
    </form>
</div>

<!--下线服务-->
<div id="dlg-undeploy" style="display:none">

</div>

<!--更多命令-->
<div id="dlg-other-command" class="form-horizontal" style="display: none">
    <div class="form-group">
        <div class="col-sm-3"><label class="w100 control-label"><input type="radio" value="setLog" name="checkCmdRadio" checked> 设置日志等级</label></div>
        <div class="col-sm-9">
            <select name="setLog" class="form-control">
                <option value=""></option>
                <option value="tars.setloglevel NONE">NONE</option>
                <option value="tars.setloglevel DEBUG">DEBUG</option>
                <option value="tars.setloglevel INFO">INFO</option>
                <option value="tars.setloglevel WARN">WARN</option>
                <option value="tars.setloglevel ERROR">ERROR</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-3"><label class="w100 control-label"><input type="radio" value="pushFile" name="checkCmdRadio"> PUSH配置文件</label></div>
        <div class="col-sm-9">
            <select name="pushFile" class="form-control" disabled></select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-3"><label class="w100 control-label"><input type="radio" value="customCmd" name="checkCmdRadio"> 发送自定义命令</label></div>
        <div class="col-sm-9">
            <input type="text" class="form-control" name="customCmd" disabled>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-3"><label class="w100 control-label"><input type="radio" value="viewLink" name="checkCmdRadio"> 查看服务链接</label></div>
        <div class="col-sm-9">

        </div>
    </div>
</div>


<script type="text/html" id="seviceTpl">
    <table class="table table-bordered" id="table">
        <thead>
            <tr>
                <!--<th><label><input type="checkbox" onchange="checkAll(this)"></label></th>-->
                <th>服务</th>
                <th>节点</th>
                <th>启用Set</th>
                <th>Set名</th>
                <th>Set区</th>
                <th>Set组</th>
                <th>设置状态</th>
                <th>当前状态</th>
				<th>流量状态</th>
                <th>进程ID</th>
                <th>版本</th>
                <th>发布时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        {{each data as it}}
        <tr>
            <!--<td><label><input type="checkbox" class="chks" value="{{it.id}}"></label></td>-->
            <td><a href="#;" onclick="viewStatusOfServer({{it.id}})">{{it.server_name}}</a></td>
            <td>{{it.node_name}}</td>
            <td>{{if it.enable_set=='true'}}是{{else}}否{{/if}}</td>
            <td>{{it.set_name}}</td>
            <td>{{it.set_area}}</td>
            <td>{{it.set_group}}</td>
            <td>{{if it.setting_state=='active'}}<span class="label label-success">active</span>{{else}}<span class="label label-danger">inactive</span>{{/if}}</td>
            <td class="get_curr_status" data-serviceid="{{it.id}}"></td>
			<td>{{if it.gridflag=='NORMAL'}}<span class="label label-success">正常</span>{{else}}<span class="label label-danger">无流量</span>{{/if}}</td>
            <td>{{it.process_id}}</td>
            <td>{{it.patch_version}}</td>
            <td>{{it.patch_time}}</td>
            <td>
                <a href="#;" onclick="updateServer('{{it.id}}','{{it.server_name}}','{{it.node_name}}','{{it.bak_flag}}','{{it.template_name}}','{{it.server_type}}','{{it.enable_set}}','{{it.set_name}}','{{it.set_area}}','{{it.set_group}}','{{it.async_thread_num}}','{{it.base_path}}','{{it.exe_path}}','{{it.start_script_path}}','{{it.stop_script_path}}','{{it.monitor_script_path}}','{{it.gridflag}}')">编辑</a> |
                <a href="#;" onclick="undeployServer({{it.id}},'{{it.setting_state}}')">下线</a> |
                <a href="#;" onclick="restartServer({{it.id}})">重启</a> |
                <a href="#;" onclick="stopServer({{it.id}})">停止</a> |
                <a href="#;"  onclick="showAdapter({{it.id}},'{{it.server_name}}','{{it.node_name}}')">管理Servant</a> |
                <a href="#;" onclick="openCmdDlg('{{it.application}}','{{it.server_name}}',{{it.id}})">更多命令</a>
            </td>
        </tr>
        {{/each}}
        </tbody>
    </table>
</script>

<script type="text/html" id="servant-tpl">
    <table class="table table-bordered" id="servant-list">
        <thead>
            <tr>
                <th>Servant名</th>
                <th>绑定地址</th>
                <th>线程数</th>
                <th>最大<br>连接数</th>
                <th>队列最大<br>长度</th>
                <th>队列超时<br>时间(ms)</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        {{each data as it}}
            <tr>
                <td class="servant">{{it.servant}}</td>
                <td class="end-point">{{it.endpoint}}</td>
                <td class="thread-num">{{it.thread_num}}</td>
                <td class="max-connections">{{it.max_connections}}</td>
                <td class="queuecap">{{it.queuecap}}</td>
                <td class="queuetimeout">{{it.queuetimeout}}</td>
                <td>
                    <a href="#;" class="bs" onclick="updateAdapter({{it.id}},this,'{{it.protocol}}','{{it.handlegroup}}','{{it.allow_ip}}')">编辑</a>
                    <a href="#;" class="bs" onclick="deleteAdapter({{it.id}})">删除</a>
                </td>
            </tr>
        {{/each}}
        </tbody>
    </table>
</script>

</body>
</html>
